extends NodeState


@export var igorBoss: IgorBoss

# 渐变消失的标志
var gradient_alpha := false


func _on_process(delta : float) -> void:
	process_die(delta)



func _on_enter() -> void:
	igorBoss.collisionShape.set_deferred("disabled", true)
	# 进入死亡时不允许再接收伤害
	igorBoss.damageReceiver.set_deferred("monitorable", false)

	igorBoss.animationPlayer.play(BasicEnemy.ANIMATION_DEATH)
	# 进入时透明度设置为1
	igorBoss.modulate.a = 1.0
	gradient_alpha = false

	SoundPlayer.play_death()



# 动画结束后逐渐消失
func on_death_animation_finished():
	await get_tree().create_timer(1).timeout
	gradient_alpha = true


func process_die(delta: float):
	if gradient_alpha:
		igorBoss.modulate.a -= delta * igorBoss.dissipate_speed
		if igorBoss.modulate.a <= 0.001:
			igorBoss.queue_free()
